home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / Action Atoms [inaa] Example / atom2.c < prev    next >
Encoding:
Text File  |  1994-11-15  |  7.7 KB  |  228 lines  |  [TEXT/MPS ]

  1. //
  2. //    Atom2.c
  3. //
  4. //
  5. //    atom2.c
  6. //
  7. //        Demonstration of a format2 action atom.
  8. //
  9. //        A dialog is provided that allows the user to select
  10. //        the return value for the action atom. 
  11. //
  12. //        Scriptwriters should be aware that the return values
  13. //        and the actions that they invoke from the installer
  14. //        are different depending on which format of action atom
  15. //        is being used. 
  16. //
  17. //        It is recommended that the constants 
  18. //            'kActionAtomResultFatalError'    <= -1
  19. //            'kActionAtomResultContinue'        <= 0
  20. //            'kActionAtomResultCancel'        <= 1
  21. //        be used when working with format2 action atoms.
  22. //        These constants are defined in "ActionAtomHeader.h"
  23. //        and are designed for use with format2 action atoms.
  24. //
  25. //        NOTE: Displaying dialogs from within an action atom 
  26. //        can enhance or detract from the user experience, and 
  27. //        should be done with consideration to the overall flow
  28. //        of installation. A good rule of thumb is to never display
  29. //        dialogs from an action atom unless absolutely necessary.
  30. //        This example is very useful in demonstrating behavior of
  31. //        the installer in regards to return values from an action
  32. //        atom, but is a terrible example of user interface design.
  33. //
  34. //        mark young • 08/18/94
  35. //
  36. //        Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
  37. //
  38.  
  39.  
  40. #include <Traps.h>
  41. #include <Types.h>
  42. #include <dialogs.h>
  43. #include <TextUtils.h>
  44.  
  45. // these lines have been added for Wasabi Installer Debugger support
  46. #include "CallbackDispatcherHeader.h"
  47. #include "ActionHandlerHeader.h"
  48. #include "InstallerMemoryFuncsHeader.h"
  49.  
  50. // this line replaces #include "ActionAtomIntf.h" used in Installer 3.x action atoms
  51. #include "ActionAtomHeader.h"
  52.  
  53. // this is needed for highliting the default button in dialog
  54. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  55.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  56.  
  57. // this is used to print one line out to the Wasabi Installer Debugger 
  58. void PrintLine( ProcPtr pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 );
  59.  
  60. // this function sends text out to the Wasabi Installer Debugger
  61. void RegisterScriptAction(     CallBackProcPtr    pCallBackProcPtr,
  62.                             short            actionClassID,
  63.                             short            actionIdentifier,
  64.                             void*            param0,
  65.                             void*            param1,
  66.                             void*            param2,
  67.                             void*            param3,
  68.                             void*            resultPtr  );
  69.  
  70. // print the parameter block record information to Wasabi Installer Debugger
  71. void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr );
  72.  
  73. // NOTE: The name of this function 'ActionAtomFormat2' should
  74. // match that specified in the -m option for the line in the
  75. // makefile that compiles this action atom.
  76. ActionAtomResult ActionAtomFormat2( ActionAtom2PBPtr atomRecPtr )
  77. {
  78.  
  79.     DialogPtr    theDialog;                        // for dialog
  80.     OSErr        theOSError = 0;                    // for errors
  81.     
  82.     short        theItemHit;                        // gets user response from ModalDialog()
  83.     short        iType;                            // gets control type from GetDItem()
  84.     Handle        iHandle;                        // gets control handle from GetDItem()
  85.     Rect         iRect;                            // gets control rect from GetDItem()
  86.     
  87.     short        currRadioButton = 2;            // current selected radio button
  88.     short        gettingUserResponse = true;        // flag for while loop
  89.     
  90.     short        theStatus = 0;                    // value to return from function
  91.  
  92.     // print the parameter block record information to Wasabi Installer Debugger
  93.     PrintAAParamBlock( atomRecPtr );
  94.  
  95.     // retrieve DLOG/DITL 130 from compiled resource script
  96.     theDialog = GetNewDialog( 130, nil, (WindowPtr) -1 );
  97.  
  98.     // activate OK button when enter or return key is pressed
  99.     theOSError = SetDialogDefaultItem( theDialog, 1 );
  100.  
  101.     // set up the radio button group ( controls 2 - 4 )
  102.     GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
  103.     SetCtlValue( (ControlHandle) iHandle, 1 );    
  104.     
  105.     GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
  106.     SetCtlValue( (ControlHandle) iHandle, 0 );    
  107.     
  108.     GetDItem( theDialog, 4, &iType, &iHandle, &iRect);
  109.     SetCtlValue(  (ControlHandle) iHandle, 0 );    
  110.     
  111.     // select the new dialog
  112.     SelectWindow( (WindowPtr) theDialog );
  113.     
  114.     // show the new dialog
  115.     ShowWindow( (WindowPtr) theDialog );
  116.     
  117.     // keep getting response from user until
  118.     // the OK is activated in the new dialog
  119.     gettingUserResponse = true;
  120.     while ( gettingUserResponse )
  121.         {
  122.         // get user selection from the new dialog
  123.         ModalDialog( nil, &theItemHit );
  124.         
  125.         switch ( theItemHit )
  126.             {
  127.             // first control is the OK key
  128.             case( 1 ) : 
  129.                         // exit loop
  130.                         gettingUserResponse = false;
  131.                         break;
  132.                         
  133.             // all other controls in dialog are radio buttons
  134.             default :     
  135.                         // continue with loop
  136.                         gettingUserResponse = true;
  137.                         
  138.                         // if the radio button selection changed
  139.                         if ( currRadioButton != theItemHit )
  140.                             {
  141.                             // turn previous radio button off
  142.                             GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
  143.                             SetCtlValue(  (ControlHandle) iHandle, 0 );    
  144.         
  145.                             // turn current radio button on
  146.                             GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
  147.                             SetCtlValue(  (ControlHandle) iHandle, 1 );    
  148.         
  149.                             // save current radio button choice
  150.                             currRadioButton = theItemHit;
  151.                             }
  152.                         break;
  153.             }// switch
  154.  
  155.         }// while
  156.         
  157.     // get rid of the new dialog
  158.     DisposDialog( theDialog );
  159.  
  160.     // select a value to return from this function according to
  161.     // which radio button was selected in the dialog
  162.     switch ( currRadioButton )
  163.         {
  164.         // return 0
  165.         case( 2 ) : theStatus = kActionAtomResultContinue;    // user selected return 0
  166.                     break;
  167.                     
  168.         // return 1
  169.         case( 3 ) : theStatus = kActionAtomResultCancel;    // user selected return 1
  170.                     break;
  171.                     
  172.         // return -1
  173.         case( 4 ) : theStatus = kActionAtomResultFatalError;// user selected return -1
  174.                     break;
  175.         }
  176.         
  177.     // return value selected by user in dialog
  178.     return( theStatus );
  179.  
  180. }
  181.  
  182. // shoot one line of text out to the Wasabi Installer Debugger
  183. void PrintLine( ProcPtr pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
  184. {
  185.     long    theResult;
  186.     RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );    
  187. }
  188.  
  189. // print a series of formatted lines describing the parameter block
  190. // received by the action atom out to the Wasabi Installer Debugger
  191. void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr )
  192. {
  193.     Str255        numStr;
  194.     
  195.     PrintLine( atomRecPtr->fCallBackProcPtr, "\p\n", "\pParameter Block for Action Atom Format2...", "\p", "\p" );
  196.     
  197.     NumToString( atomRecPtr->fMessageID, numStr );
  198.     PrintLine(   atomRecPtr->fCallBackProcPtr, "\p", "\pfMessageID : ", numStr,  "\p" );
  199.     
  200.     NumToString( (long) atomRecPtr->fStaticDataHdl, numStr );
  201.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfStaticDataHdl : ", numStr, "\p", "\p" );
  202.     
  203.     NumToString( (long) atomRecPtr->fTargetVRefNum, numStr );
  204.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfTargetVRefNum : ", numStr, "\p", "\p" );
  205.     
  206.     NumToString( (long) atomRecPtr->fTargetFolderDirID, numStr );
  207.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfTargetFolderDirID : ", numStr, "\p", "\p" );
  208.     
  209.     NumToString( (long) atomRecPtr->fSystemVRefNum, numStr );
  210.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfSystemVRefNum : ", numStr, "\p", "\p" );
  211.     
  212.     NumToString( (long) atomRecPtr->fSystemBlessedDirID, numStr );
  213.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfSystemBlessedDirID : ", numStr, "\p", "\p" );
  214.     
  215.     NumToString( (long) atomRecPtr->fRefCon, numStr );
  216.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfRefCon : ", numStr, "\p", "\p" );
  217.     
  218.     NumToString( (long) atomRecPtr->fDoingInstall, numStr );
  219.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfDoingInstall : ", numStr, "\p", "\p" );
  220.     
  221.     NumToString( (long) atomRecPtr->fDidLiveUpdate, numStr );
  222.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfDidLiveUpdate : ", numStr, "\p", "\p" );
  223.     
  224.     NumToString( (long) atomRecPtr->fInstallerTempDirID, numStr );
  225.     PrintLine(   atomRecPtr->fCallBackProcPtr,  "\pfInstallerTempDirID : ", numStr, "\p", "\p\n" );
  226.     
  227. }
  228.